package com.quanyan.stadium.web.admin;

import com.quanyan.api.APIResponse;
import com.quanyan.place.entity.apiresp.RespCityInfos;
import com.quanyan.stadium.api.req.ReqId;
import com.quanyan.stadium.api.req.ReqIdAndPage;
import com.quanyan.stadium.entity.vo.PlaceInfo;
import com.quanyan.stadium.service.commonComponent.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author dongshenglin
 * @date 2016/7/30  15:56
 */
@RestController
@RequestMapping("/admin/api/stadium/base")
public class BaseController {

    @Autowired
    private BaseService baseService;

    /**
     * 根据[关键字]搜索俱乐部的信息
     *
     * */
    @RequestMapping(value="/queryClubByKey", method = RequestMethod.POST)
    public APIResponse<?> queryClubByKey(@RequestBody ReqIdAndPage reqIdAndPage)  {
        if (null == reqIdAndPage.getKeyName()) {
            return APIResponse.returnFail("keyName不能为空");
        }
       return APIResponse.returnSuccess(baseService.queryClubMsgByKey(reqIdAndPage.getKeyName(), reqIdAndPage.getCityId(),
               reqIdAndPage.getDistrictId(), reqIdAndPage.getPageNo(), reqIdAndPage.getPageSize()));
    }


    /**
     * 获取城市列表
     *
     * */
    @RequestMapping(value="/queryUsableCity", method = RequestMethod.POST)
    public APIResponse<?> queryUsableCity()  {
        List<RespCityInfos> msg = baseService.queryRespCityInfos();
        return APIResponse.returnSuccess(msg);
    }

    /**
     * 获取某城市下的场馆列表
     *
     * */
    @RequestMapping(value="/queryPlaceInfoByDistrictId", method = RequestMethod.POST)
    public APIResponse<?> queryPlaceInfoByDistrictId(@RequestBody ReqId reqId)  {
        if (null == reqId.getCityId()) {
            return APIResponse.returnFail("cityId不能为空");
        }
        if (null == reqId.getDistrictId()) {
            return APIResponse.returnFail("districtId不能为空");
        }
        List<PlaceInfo> msg = baseService.queryPlaceInfoByDistrictId(reqId.getCityId(), reqId.getDistrictId(), reqId.getCategoryId());
        return APIResponse.returnSuccess(msg);
    }
}
